#include <stdio.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
	char buf[1];
	int flag = 1;
    printf("打开文件1.txt\n");
    int fd1 = open("./src/1.txt",O_RDONLY);
    if(fd1 == -1){
		perror("打开失败"); 
    	return;
	}
    printf("创建文件2.txt\n");
    int fd2 = creat("./src/2.txt",777);
    if(fd2 == -1){
		perror("创建失败"); 
    	return;
	}
        printf("文件\n");
	int ret1,ret2;
	while(flag) {
		ret1 = read(fd1,buf,sizeof(buf));
		if(ret1 == -1){
			perror("复制失败"); 
    		return;
		}
		flag = ret1; 
		if(flag== 0){
			printf("复制完成\n"); 
			break;
		}
		ret2 = write(fd2,buf,ret1);
		if(ret2 == -1){
			perror("粘贴失败"); 
    		return;
		}
			 
	}
	close(fd1);
	close(fd2);
    return 0;
}

